package com.testMvc.myshiroFiter;

import com.core.safe.AuthRealm;
import com.core.safe.SafeOterInfo;
import com.core.safe.SafeUserInfo;
import com.core.safe.UserToken;
import com.testMvc.UserDao.User;
import com.testMvc.UserDao.UserFactory;

public class MyAuthRealm extends AuthRealm {
    @Override
    protected SafeUserInfo doGetSafeUserInfo(UserToken userToken) {
        SafeUserInfo safeUserInfo = new SafeUserInfo();
        User user = UserFactory.getUser(userToken);
        if (user == null) {
            safeUserInfo = null;
        } else {
            safeUserInfo.setUser(user);
            safeUserInfo.setId(user.getUserid());
        }
        return safeUserInfo;
    }

    @Override
    protected SafeOterInfo doGetSafeOterInfo(Object user) {
        User u = (User) user;
        SafeOterInfo safeOterInfo = new SafeOterInfo();
        safeOterInfo.setResourceList(UserFactory.getRescource(u.getUserid()));
        safeOterInfo.setRoleList(UserFactory.getRole(u.getUserid()));
        return safeOterInfo;
    }
}
